package com.zhouyong.leetcode.选出出现频率最高的字母面试题;

import java.util.HashMap;
import java.util.Map;

/**
 * @Author 99
 * @Date 2022/9/7 19:39
 * @Version 1.0
 */
public class Test {

    public static void main(String[] args) {
        chooseNumber("aabbccc");
    }

    public static void chooseNumber(String a) {
        char[] array = a.toCharArray();
        HashMap<Character, Integer> map = new HashMap<>();
        int index = 1, maxValue = 0, maxKey = 0;
        for (char c : array) {
            if (map.containsKey(c)) {
                map.put(c, ++index);
            } else {
                index = 1;
                map.put(c, index);
            }
        }
        for (Map.Entry<Character, Integer> entry : map.entrySet()) {
            if (entry.getValue() > maxValue) {
                maxValue = entry.getValue();
                maxKey = entry.getKey();
            }
        }
        System.out.println((char) maxKey);
    }
}
